import http from '../../tool/http'
import api from '../../tool/api'
const state = {
    tableData: [],
    dangqian: 1,
    page:0,
    maidanDishes:[],
}

const getters={
    requestPage:state=>(state.dangqian-1)*10,
    totalPage:state=>state.page
}

const actions = {
    //餐桌总数据
    getTableData({
        commit 
    }, num) {
        return http({
            url: api.getTableData,
            method: 'post',
            data: {
                num1: num,
                num2: 10
            },
        }).then(res => {
            commit('getTableData', res)
            return res
        }).catch(err=>{
            return err
        })
    },
    //餐桌分页数据
    getTablePage({commit}) {
        return http({
            url: api.getTablePage,
            method: 'post'
        }).then(res => {
            console.log(res);
            commit('getTablePage',res.data.page)
        })
    },
    //餐桌空闲状态改变
    occupyState({
        commit
    }, num) {
        return http({
            url: api.occupyState,
            method: 'post',
            data: {
                number: num
            }
        }).then(res => {
            console.log(res);
            return res
        })
    },
    //餐桌占用状态改变
    freeState({
        commit
    }, num) {
        return http({
            url: api.freeState,
            method: 'post',
            data: {
                number: num
            }
        }).then(res => {
            console.log(res);
            return res
        })
    },
    //改变当前页
    changeCurrentPage({commit},val){
        commit('changeCurrentPage',val)
    },
    //买单查订单
    selectDishes({commit},num){
        return http({
            url:api.unfinDishes,
            method:'post',
            data:{seats_id:num}
        }).then(res=>{
            // console.log(res);
            commit('selectDishes',res.data.data)
            return res
        })
    },
    //现金买单完成订单
    cashMaidan({commit},num){
        return http({
            url:api.finChange,
            method:'post',
            data:{seats_id:num}
        }).then(res=>{
            console.log(res);
            return res
        })
    },
    //会员买单完成订单
    memberMaidan({commit},num){
        return http({
            url:api.finChangeMember,
            method:'post',
            data:{seats_id:num}
        }).then(res=>{
            console.log(res);
            return res
        })
    },
    //会员买单扣钱验证
    selectMember({commit},obj){
        console.log(obj.tel,obj.password,obj.total);
        
        return http({
            url:api.memberSelect,
            method:'post',
            data:{tel:obj.tel,password:obj.password,total:obj.total}
        }).then(res=>{
            console.log(res.data.code);
            return res
        })
    },
    dangqianInit1({commit}){
        commit('dangqianInit1')
    }
}

const mutations = {
    getTableData(state, obj) {
        state.tableData = obj.data.data
    },
    getTablePage(state,num){
        state.page=num
    },
    changeCurrentPage(state,num){
        state.dangqian=num
    },
    selectDishes(state,obj){
        state.maidanDishes=obj
    },
    dangqianInit1(state){
        state.dangqian=1
    }
}

export default {
    state,
    actions,
    mutations,
    getters
}